﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Pavilion.GameTools;

namespace Pavilion.Locks
{
    public enum InputCondition { Pressed, Released, IsDown, IsUp }
    public class CharacterInputLock : ILock
    {
        public CharacterInput Input { get; set; }
        public InputCondition InputCondition { get; set; }
        public string GameItemName { get; set; }

        public ILock Clone()
        {
            return new CharacterInputLock()
            {
                GameItemName = this.GameItemName,
                Input = this.Input,
                InputCondition = this.InputCondition
            };
        }

        public void Deserialize(XElement lockElement, string resourceName)
        {
            Input = GameEngine.ParseObject<CharacterInput>(lockElement.Attribute("Input").Value);
            InputCondition = GameEngine.ParseObject<InputCondition>(lockElement.Attribute("InputCondition").Value);
        }

        public XElement Serialize()
        {
            XElement lockElement = new XElement("Lock");

            lockElement.Add(new XAttribute("Input", Input));
            lockElement.Add(new XAttribute("InputCondition", InputCondition));

            return lockElement;
        }

        public LockMonitorBase CreateLockMonitor(GameItem gameItem)
        {
            return new CharacterInputLockMonitor(this);
        }

        public override string ToString()
        {
            return this.GetType().Name;
        }
    }
}
